﻿using System;
using System.Collections.ObjectModel;
using ZOIL.DataModel;

namespace ZOIL.DataBackend.Server
{
    /// <summary>
    /// Represents the status of the Database
    /// </summary>
    public enum DatabaseStatus {Running, Stopped};
    
    /// <summary>
    /// Configuration Class for one Database
    /// </summary>
    public class DatabaseConfiguration : BasePropertyChange
    {
        public DatabaseConfiguration()
        {
            Users = new ObservableCollection<DatabaseUser>();
            Status = DatabaseStatus.Stopped;
            DeleteInterval = 10 * 1000;
            Activate();
        }

        /// <summary>
        /// Deactivates the Server
        /// </summary>
        public void Deactivate()
        {
            Server = null;
        }

        /// <summary>
        /// Activates the Server
        /// </summary>
        public void Activate()
        {
            Server = new DB4OServer();
        }

        #region Properties

        private int _deleteInterval;
        public int DeleteInterval
        {
            get
            {
                return _deleteInterval;
            }
            set
            {
                _deleteInterval = value;
                RaisePropertyChanged("DeleteInterval");
            }
        }

        private int _port;
        public int Port
        {
            get
            {
                return _port;
            }
            set
            {
                _port = value;
                RaisePropertyChanged("Port");
            }
        }

        private String _databaseFile;
        public String DatabaseFile
        {
            get
            {
                return _databaseFile;
            }
            set
            {
                _databaseFile = value;
                RaisePropertyChanged("DatabaseFile");
            }
        }

        public String DatabaseFileWithPath
        {
            get
            {
                return ZOIL.DataBackend.Server.Server.getInstance().DatabaseDirectory + "\\" + DatabaseFile + ".db4o";
            }
        }

        private String _name;
        public String Name
        {
            get
            {
                return _name;
            }
            set
            {
                _name = value;
                RaisePropertyChanged("Name");
            }
        }

        private String _description;
        public String Description
        {
            get
            {
                return _description;
            }
            set
            {
                _description = value;
                RaisePropertyChanged("Description");
            }
        }

        public ObservableCollection<DatabaseUser> Users { get; private set; }

        private DatabaseStatus _status;
        public DatabaseStatus Status
        { 
            get
            {
                return _status;
            }
            set
            {
                _status = value;
                RaisePropertyChanged("Status");
            }
        }

        private bool _useMemoryIOAdapter;
        public bool UseMemoryIOAdapter
        {
            get
            {
                return _useMemoryIOAdapter;
            }
            set
            {
                _useMemoryIOAdapter = value;
                RaisePropertyChanged("UseMemoryIOAdapter");
            }
        }

        private DB4OServer _server;
        public DB4OServer Server
        {
            get
            {
                return _server;
            }
            private set
            {
                _server = value;
            }
        }

        #endregion
    }
    
}
